<div class="uimssVarieties" style="height: 100%;width:100%;overflow:auto;position: relative;">
    <div class="button-group-head" style="">
        <span class="hrp-btn hrp-btn-add" id="openDialog"><i class="fa fa-plus" style="padding-right: 4px;"></i>添加</span>
        <span  class="hrp-btn hrp-btn-refresh"><i class="fa fa-refresh" style="padding-right: 4px;"></i>刷新</span>
    </div>
    <div>
        <table id="dg" class="easyui-datagrid" style="width:100%;">
            <!--<thead>-->
            <!--<tr>-->
            <!--<th  width="15%">Item ID(15%)</th>-->
            <!--<th  width="15%">Product(15%)</th>-->
            <!--<th  width="15%">List Price(15%)</th>-->
            <!--<th  width="15%">List Price(15%)</th>-->
            <!--<th width="15%">List Price(15%)</th>-->
            <!--</tr>-->
            <!--</thead>-->
        </table>
    </div>

    <div id="editActionDialog"  class="ss-dialog" style="width:600px;height: 300px;">
        <span class="ss-dialog-close" style="">X</span>
        <div class="ss-dialog-head" style="">
            添加
        </div>
        <div class="ss-dialog-content">
            <div class="row" style="height: 60px;">
                <input type="hidden" id="idkey" value="-1"/>
                <span style="width:15%;height:60px;line-height:60px;float:left;text-align: center;">收货方名称:</span>
                <span style="width:35%;float:left;"><input  id="name" type="text" placeholder="请输入收货方名称名称" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
                <span style="width:15%;height:60px;line-height:60px;float:left;text-align: center;">联系人:</span>
                <span style="width:35%;float:left;"><input  id="lxr" type="text" placeholder="联系人名称" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
            </div>
            <div class="row" style="height: 60px;">
                <span style="width:15%;height:60px;line-height:60px;float:left;text-align: center;">联系电话:</span>
                <span style="width:35%;float:left;"><input  id="lxdh" type="text" placeholder="手机号码" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
                <span style="width:15%;height:60px;line-height:60px;float:left;text-align: center;">地址:</span>
                <span style="width:35%;float:left;"><input  id="address" type="text" placeholder="手机号码" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>

            </div>
            <div class="row" style="height: 60px;">
                <span style="width:15%;height:60px;line-height:60px;float:left;text-align: center;">备注:</span>
                <span style="width:35%;float:left;"><input  id="memo" type="text" placeholder="备注" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
                <span style="width:15%;height:60px;line-height:60px;float:left;text-align: center;">停用标志</span>
                <span style="width:35%;float:left;padding-top: 21px;font-size: 14px;cursor: pointer;">
                    <span class="self-radio" data-radio="true" id="qy" data-value="1"><i class="fa fa-dot-circle-o"></i>启用</span>
                    <span class="self-radio" id="ty" data-value="0"><i class="fa fa-circle-o"></i>停用</span>
                </span>
            </div>
        </div>
        <div  class="ss-dialog-head" style="">
            <span class="hrp-btn hrp-btn-delete" style="float: right;" id="btn-cancel"><i class="fa fa-close" style="padding-right: 4px;"></i>取消</span>
            <span class="hrp-btn hrp-btn-add" style="float: right;" id="btn-save"><i class="fa fa-plus" style="padding-right: 4px;"></i>添加</span>
        </div>
    </div>
    <div id="mask-model" class="mask-model" style=""></div>


</div>


<script type="text/javascript">

    var dHeight = $(".uimssVarieties").height()-42;

    var UserIndexPage={
        tableName:"UIMSS_RECEIVERINFO",
        loginUser:{},
        insertTime:'',
        updateTime:'',
        init:function () {
            this.initLoginUser();
        },
        initLoginUser:function () {
            $.post("common/getLoginUser", function (result) {

                UserIndexPage.loginUser=result.data;
                UserIndexPage.initGrid();
                UserIndexPage.initEvnets();
            })
        },
        initEvnets:function () {
            var that = this;
            $(window).resize(function () {
                $('#dg').datagrid("resize")
            })
            $("#openDialog").on("click",function () {
                $("#idkey").val("-1");

                var nowDate = new Date();
                UserIndexPage.insertTime=nowDate.getFullYear()+'-'+nowDate.getMonth()+'-'+nowDate.getDate();
                UserIndexPage.updateTime=nowDate.getFullYear()+'-'+nowDate.getMonth()+'-'+nowDate.getDate();


                $.post("jxkhzb/getMaxZbid",function (result) {
                    $("#zbdm").val(result);
                })
                $('#editActionDialog').slideDown(300);
                $("#mask-model").slideDown(300);
            })

            $(".ss-dialog-close").on("click",function () {
                $('#editActionDialog').slideUp(300);
                $("#mask-model").slideUp(300);
            })

            $("#btn-save").on("click",function () {
                that.saveData();
            })

            $("#btn-cancel").on("click",function () {
                $('#editActionDialog').slideUp(300);
                $("#mask-model").slideUp(300);
            })

            //修改
            $(".uimssVarieties").on("click",".btn-edit",function () {
                var id = $(this).attr("data-id");
                var name = $.trim($(this).attr("data-name"));

                var lxr = $.trim($(this).attr("data-lxr"));
                var lxdh = $.trim($(this).attr("data-lxdh"));
                var address = $.trim($(this).attr("data-address"));
                var memo = $.trim($(this).attr("data-memo"));



                var tybz = $(this).attr("data-tybz");

                var tybz = $(this).attr("data-tybz");
                var nowDate = new Date();
                UserIndexPage.updateTime=nowDate.getFullYear()+'-'+nowDate.getMonth()+'-'+nowDate.getDate();
                UserIndexPage.insertTime = $(this).attr("date-insertTime");

                $("#idkey").val(id);
                $("#name").val(name);

                $("#lxr").val(lxr);
                $("#lxdh").val(lxdh);
                $("#address").val(address);
                $("#memo").val(memo);

                $(".self-radio[data-value='"+tybz+"']").click()
                $('#editActionDialog').slideDown(300);
                $("#mask-model").slideDown(300);
                //that.editKhzb()
            })
        },
        saveData:function () {
            var that = this;
            var name = $.trim($("#name").val());
            var lxr = $.trim($("#lxr").val());
            var lxdh =$.trim($("#lxdh").val());
            var address =$.trim($("#address").val()) ;
            var memo = $.trim($("#memo").val());

            if ($.trim(name) == "") {
                $.messager.show({title: '提示', msg: '分类名称不能为空', timeout: 1000, showType: 'slide'});
                return;
            }
            var tybz = $(".self-radio[data-radio='true']").attr("data-value");

            var czry =UserIndexPage.loginUser.username;

            $.post("common/commonAdd", {
                "id":$("#idkey").val(),
                "name":"'"+name+"'",
                "lxr":"'"+lxr+"'",
                "lxdh":"'"+lxdh+"'",
                "address":"'"+address+"'",
                "memo":"'"+memo+"'",
                "state":tybz,
                "tableName":that.tableName,
                "insertTime":"'"+UserIndexPage.insertTime+"'",
                "updateTime":"'"+UserIndexPage.updateTime+"'",
                "czry":"'"+czry+"'"
            }, function (result) {
                if (result.status == 200) {
                    $('#editActionDialog').slideUp(300);
                    $("#mask-model").slideUp(300);
                    that.initGrid();
                    $.messager.show({title: '提示', msg: '保存成功', timeout: 1000, showType: 'slide'});
                } else if(result.status == 600){
                    $.messager.show({title: '提示', msg: '已存在同名称收货方', timeout: 1000, showType: 'slide'});
                } else {
                    $.messager.show({title: '提示', msg: '保存失败', timeout: 1000, showType: 'slide'});
                }
            })
        },
        initGrid:function () {
            $('#dg').datagrid({
                url: "common/commonGetListByPage",
                queryParams: {
                    tableName: UserIndexPage.tableName
                },
                pagination: true,
                singleSelect: true,
                height:dHeight,   //表格高度，可指定高度，可自动
                pageNumber: 1,
                pageSize: 15,
                pageList: [15, 30],
                fitColumns:true,
                loadMsg: "正在加载数据",
                nowrap: false,
                striped: true,  //奇偶行是否使用不同的颜色
                columns:[
                    [
                        {field:'id',title:'编号',width:"10%"},
                        {field:'name',title:'供货方名称',width:"20%"},
                        {field:'lxr',title:'联系人',width:"10%"},
                        {field:'lxdh',title:'联系电话',width:"15%"},
                        {field:'address',title:'详细地址',width:"15%"},
                        {field:'memo',title:'备注',width:"20%"},
                        {
                            field: 'edit', title: '操作', width: "10%",
                            formatter: function (value, row, index) {
                                return "<a class='btn-edit' href='#' data-id='"+row.id+"'  data-name='"+row.name+"' data-tybz='"+row.state+"' data-lxr='"+row.lxr+"' data-lxdh='"+row.lxdh+"' data-address='"+row.address+"' data-memo='"+row.memo+"'  date-insertTime='"+row.insertTime+"'>修改</a>"
                            }
                        }
                    ]
                ]
            });

        }
    }
    $(function () {
        UserIndexPage.init();
    })
</script>